package com.cj.common.web.filter;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.apache.cxf.common.util.StringUtils;

public class ClearNullHttpServletRequestWrapper extends HttpServletRequestWrapper{

	public ClearNullHttpServletRequestWrapper(HttpServletRequest servletRequest) { 
		super(servletRequest); 
	} 
	
	@Override
	public Map getParameterMap() {
		Map<String,String[]> old = super.getParameterMap();
		Map<String,String[]> params = new HashMap<String,String[]>();
		Iterator<Entry<String, String[]>> keyIt = old.entrySet().iterator();
		while(keyIt.hasNext()){
			Entry<String, String[]> entry = keyIt.next();
			String key = entry.getKey();
			String[] value = entry.getValue();
			if(value == null || value.length == 0)
				continue;
			if(value.length == 1 && StringUtils.isEmpty(value[0]))
				continue;
			params.put(key, value);
		}
		return params;
	}
}
